<?php

namespace api\modules\v1\controllers;

use yii\rest\ActiveController;
use yii\data\ActiveDataProvider;

class GoodsController extends ActiveController
{
    public $modelClass = 'api\models\Goods';

    public function actions()
    {
        $actions = parent::actions();
        // 禁用""index,delete" 和 "create" 操作
        unset($actions['index'],$actions['delete'], $actions['create']);

        return $actions;
    }

    //重写index的业务实现
    public function actionIndex()
    {

        $modelClass = $this->modelClass;
        return new ActiveDataProvider([
            'query' => $modelClass::find()->where(['id' => 1])->asArray(),

            'pagination' => false
        ]);
    }

    /**
     * @SWG\Post(path="/delivery/order-sheet/{shippingNumber}/{sign}",
     *   tags={"Delivery"},
     *   summary="Sync order sheet result from warehouse to Glitzhome",
     *   description="从仓库同步发货结果",
     *   operationId="delivery/order-sheet",
     *   produces={"application/xml", "application/json"},
     *   @SWG\Parameter(
     *     name="shippingNumber",
     *     in="path",
     *     description="Shipping Number",
     *     required=true,
     *     type="string"
     *   ),
     *   @SWG\Parameter(
     *     name="sign",
     *     in="path",
     *     description="Sign of request parameters",
     *     required=true,
     *     type="string"
     *   ),
     *   @SWG\Parameter(
     *     name="Authorization",
     *     in="header",
     *     description="授权Token，Bearer模式",
     *     required=true,
     *     type="string"
     *   ),
     *   @SWG\Parameter(
     *     in="body",
     *     name="orderSheet",
     *     description="仓库反馈的Order sheet的结果",
     *     required=true,
     *     type="array",
     *     @SWG\Schema(ref="#/definitions/OrderSheetRequest")
     *   ),
     *
     *   @SWG\Response(response=200, @SWG\Schema(ref="#/definitions/OrderSheetResponse"), description="successful operation"),
     *   @SWG\Response(response=400,description="Bad request"),
     *   @SWG\Response(response=401,description="Not authorized"),
     *   @SWG\Response(response=404,description="Method not found"),
     *   @SWG\Response(response=405,description="Method not allowed"),
     *   @SWG\Response(response=426,description="Upgrade required"),
     *   @SWG\Response(response=429,description="Rate limit exceeded"),
     *   @SWG\Response(response=499,description="Customized business errors"),
     *   @SWG\Response(response=500,description="Internal Server Error"),
     *   security={
     *     {"Authorization": {}},
     *   }
     * )
     *
     */
    public function actionAdd()
    {
echo $str= '你好,这里是卖咖啡!';
echo '<br />';
echo iconv('GB2312', 'UTF-8', $str); //将字符串的编码从GB2312转到UTF-8
echo '<br />';
echo iconv_substr($str, 1, 1, 'UTF-8'); //按字符个数截取而非字节
print_r(iconv_get_encoding()); //得到当前页面编码信息
echo iconv_strlen($str, 'UTF-8'); //得到设定编码的字符串长度
//也有这样用的
$content = iconv("UTF-8","gbk//TRANSLIT",$content);
    }



}